import requests
import sys
import json
import datetime

now = datetime.datetime.now()
ordertime = now.strftime("%Y%m%d%H%M%S%C")

obj = {'OUTERORDERNO': 'test' + ordertime, 'RETREDIRECT': 'PAY.CHANNEL',
       'PAYCHANNEL': 'QDHF.PAY.WEIXIN.PUB', 'MESSAGE': 'SUCCESS', 'RESPCODE': '1000000',
        'OPMONEY': 1, 'ORDERTIME': ordertime, "BODY": "测试",
       'CFGPARA': {'key': '9d101c97133837e13dde2d32a5054abb', 'merchant_no': '7551000001',
                   'appid': 'wxd06dc3bbb977ecd3', 'url': "https://pay.swiftpass.cn/pay/gateway"}}

if __name__ == '__main__':
    channel = sys.argv[1]
    if channel == "noti":
        data = b'<xml><bank_type><![CDATA[GDB_CREDIT]]></bank_type>\n<charset><![CDATA[UTF-8]]></charset>\n<fee_type><![CDATA[CNY]]></fee_type>\n<is_subscribe><![CDATA[N]]></is_subscribe>\n<mch_id><![CDATA[7551000001]]></mch_id>\n<nonce_str><![CDATA[1509692060319]]></nonce_str>\n<openid><![CDATA[oywgtuKVLWFGRKu9Ilhgju4c1Nac]]></openid>\n<out_trade_no><![CDATA[test2017110314533220]]></out_trade_no>\n<out_transaction_id><![CDATA[4200000006201711032172938342]]></out_transaction_id>\n<pay_result><![CDATA[0]]></pay_result>\n<result_code><![CDATA[0]]></result_code>\n<sign><![CDATA[FC7A9B96E761DA1191EF1B6FDEB525A4]]></sign>\n<sign_type><![CDATA[MD5]]></sign_type>\n<status><![CDATA[0]]></status>\n<sub_appid><![CDATA[wxce38685bc050ef82]]></sub_appid>\n<sub_is_subscribe><![CDATA[N]]></sub_is_subscribe>\n<sub_openid><![CDATA[oHmbktwgi9BU2oO4zDgZ5A-BRPBQ]]></sub_openid>\n<time_end><![CDATA[20171103145419]]></time_end>\n<total_fee><![CDATA[1]]></total_fee>\n<trade_type><![CDATA[pay.weixin.native]]></trade_type>\n<transaction_id><![CDATA[7551000001201711037154969037]]></transaction_id>\n<version><![CDATA[2.0]]></version>\n</xml>'
        url = "http://127.0.0.1:10019/noti/swiftpass"

    if channel == 'wxc2b':
        data = json.dumps(obj)
        url = 'http://127.0.0.1:10019/swiftpass/wxc2b'
    elif channel == 'alic2b':
        data = json.dumps(obj)
        url = 'http://127.0.0.1:10019/swiftpass/alic2b'
    elif channel == 'bestpay':
        data = json.dumps(obj)
        url = 'http://127.0.0.1:10019/swiftpass/bestpay'
    elif channel == 'qqc2b':
        data = json.dumps(obj)
        url = 'http://127.0.0.1:10019/swiftpass/qqc2b'
    elif channel == 'jdc2b':
        data = json.dumps(obj)
        url = 'http://127.0.0.1:10019/swiftpass/jdc2b'
    elif channel == 'pub':
        data = json.dumps(obj)
        url = 'http://127.0.0.1:10019/swiftpass/pub'
    elif channel == 'query':
        obj['OUTERORDERNO'] = sys.argv[2]
        # obj["OUTERORDERNO"] = 'refund' + ordertime
        data = json.dumps(obj)
        url = 'http://127.0.0.1:10019/swiftpass/query'
    elif channel == 'refund':
        obj['OLDOUTERORDERNO'] = sys.argv[2]
        obj["OUTERORDERNO"] = 'refund' + ordertime
        data = json.dumps(obj)
        url = 'http://127.0.0.1:10019/swiftpass/refund'
    elif channel == 'refundquery':
        obj['OUTERORDERNO'] = sys.argv[2]
        # obj["OUTERORDERNO"] = 'refund' + ordertime
        data = json.dumps(obj)
        url = 'http://127.0.0.1:10019/swiftpass/refundquery'

    rsp = requests.post(url, data=data)
    print(rsp.content)
